package com.medicinemanager.ui;

import com.example.medicinemanager.R;
import com.medicinemanager.bean.Medicineinfo;
import com.medicinemanager.sql.MedicineManager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MedicineAdd extends BaseActivity{
	private EditText mEditTextId = null;
	private EditText mEditTextName = null;
	private EditText mEditTextNumber = null;
	private EditText mEditTextPerson = null;
	private EditText mEditTextPersonId = null;
	private Button mBtnSure = null;
	private MedicineManager mMedicineManager = null;
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add);
		
		initAction();
		initEditText();
		initButton();
	}
	
	private void initAction(){
		mMedicineManager = new MedicineManager(this);
	}
	
	private void initButton(){
		mBtnSure = (Button) findViewById(R.id.sure);
		mBtnSure.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Medicineinfo medicineinfo = new Medicineinfo();
				medicineinfo.setId(mEditTextId.getText().toString());
				medicineinfo.setName(mEditTextName.getText().toString());
				medicineinfo.setNumber(Integer.parseInt(mEditTextId.getText().toString()));
				medicineinfo.setPerson(mEditTextPerson.getText().toString());
				medicineinfo.setPersonid(mEditTextPersonId.getText().toString());
				mMedicineManager.insert(medicineinfo);
				gotoBack();
			}
		});
	}
	
	private void initEditText(){
		mEditTextId = (EditText) findViewById(R.id.ed_id);
		mEditTextName = (EditText) findViewById(R.id.ed_name);
		mEditTextNumber = (EditText) findViewById(R.id.ed_number);
		mEditTextPerson = (EditText) findViewById(R.id.ed_person);
		mEditTextPersonId = (EditText) findViewById(R.id.ed_personid);
	}
	
	@Override
	public void gotoBack() {
		// TODO Auto-generated method stub
		Intent intent = new Intent();
		intent.setClass(MedicineAdd.this, ManagerMedicineActivity.class);
		this.startActivity(intent);
	}

	@Override
	public void gotoAhead() {
		// TODO Auto-generated method stub
		
	}

}
